import os
import shutil

def ensure_directory_exists(directory):
    """Ensure that a directory exists, create it if it doesn't."""
    os.makedirs(directory, exist_ok=True)

def get_unique_filename(directory, filename):
    """Generate a unique filename in the specified directory."""
    base, ext = os.path.splitext(filename)
    counter = 1
    new_filename = filename
    
    while os.path.exists(os.path.join(directory, new_filename)):
        new_filename = f"{base}_{counter}{ext}"
        counter += 1
    
    return new_filename